//获取过去七天时间
export function getDaysTime() {
  let date = new Date();
  let base = Date.parse(date); // 转换为时间戳
  let oneDay = 24 * 3600 * 1000
  let daytimeArr = []
  for (let i = 6; i >= 0; i--) { //前七天的时间
    let now = new Date(base -= oneDay);
    let myear = now.getFullYear();
    let month = now.getMonth() + 1;
    let mday = now.getDate()
    daytimeArr.push([month >= 10 ? month : '0' + month, mday >= 10 ? mday : '0' + mday].join('-'))
  }
  let dayTimeList = []
  for (let i = daytimeArr.length - 1; i >= 0; i--) {
    dayTimeList.push(daytimeArr[i])
  }
  return dayTimeList
}
//获取过去七天时间
export function getBeforeDayTime(n) {
  n = n==null?0:n;
  let date = new Date();
  let base = Date.parse(date); // 转换为时间戳
  let oneDay = 24 * 3600 * 1000;
  let now = new Date(base -= oneDay*n);
  let myear = now.getFullYear();
  let month = now.getMonth() + 1;
  let mday = now.getDate();
  return [myear,month >= 10 ? month : '0' + month, mday >= 10 ? mday : '0' + mday].join('-')
}
//转化时间字符串
export function dateToString(date) {
  if(date==null){
    date = new Date();
  }
  let myear = date.getFullYear();
  let month = date.getMonth() + 1;
  let mday = date.getDate()
  return [myear,month >= 10 ? month : '0' + month, mday >= 10 ? mday : '0' + mday].join('-')
}
